package structs

import (
	"fmt"
	"parking/src/common"
	"time"
)

// 第三方日志记录器 zap
var logger = common.GetLogger()

type CameraInfoStruct struct {
	devId       string
	ip          string
	port        string
	ledChannel  string
	ledAddress  string
	openChannel string
	online      bool
}

type Led485ConfigStruct struct {
	name        string // 根据实际情况修改串口名称
	baud        int    // 波特率
	readTimeout time.Duration
	address     string // 通道编号
}

type Led485ConfigArrayStruct struct {
	led485Info []*Led485ConfigStruct
}

type DeviceRsp struct {
	Cmd    string `json:"cmd"`    // 命令字（序列化字段名保持小写）
	MsgID  string `json:"msgId"`  // 消息ID（JSON字段驼峰命名）
	UtcTs  int    `json:"utcTs"`  // UTC时间戳
	Status string `json:"status"` // 状态字段
	Detail string `json:"detail"`
}

type Config struct {
	ErrorShows *ErrorShows `json:"errorShows"`
}
type ErrorShows struct {
	Camera map[string]string `json:"camera"`
	Device map[string]string `json:"device"`
	Server map[string]string `json:"server"`
}

func NewDeviceRsp(cmd, msgId, status, detail string) *DeviceRsp {
	return &DeviceRsp{
		Cmd:    cmd,
		MsgID:  msgId,
		UtcTs:  int(time.Now().UTC().Unix()),
		Status: status,
		Detail: detail,
	}
}

//---------------------------------------------------------

func NewCamerasInfoStruct() *CameraInfoStruct {
	return &CameraInfoStruct{}
}

func NewLed485ConfigStruct() *Led485ConfigStruct {
	//led485连接超时限制默认5s
	defaultReadTimeout := 5 * time.Second
	return &Led485ConfigStruct{
		readTimeout: defaultReadTimeout,
	}
}

//---------------------------------------------------------

// String 方法返回一个格式化的字符串，描述 Led485ConfigStruct 的内容
func (l *Led485ConfigStruct) String() string {
	return fmt.Sprintf("Name: %s, Baud: %d, ReadTimeout: %v", l.name, l.baud, l.readTimeout)
}

func (c *CameraInfoStruct) String() string {
	return fmt.Sprintf("Device ID: %s, IP: %s, Port: %s", c.devId, c.ip, c.port)
}

func (c *CameraInfoStruct) GetDevId() string {
	return c.devId
}

func (c *CameraInfoStruct) SetDevId(devId string) {
	c.devId = devId
}

func (c *CameraInfoStruct) GetIp() string {
	return c.ip
}

func (c *CameraInfoStruct) SetIp(ip string) {
	c.ip = ip
}

func (c *CameraInfoStruct) GetPort() string {
	return c.port
}

func (c *CameraInfoStruct) SetPort(port string) {
	c.port = port
}

func (l *Led485ConfigStruct) GetName() string {
	return l.name
}

func (l *Led485ConfigStruct) SetName(name string) {
	l.name = name
}

func (l *Led485ConfigStruct) GetBaud() int {
	return l.baud
}

func (l *Led485ConfigStruct) SetBaud(baud int) {
	l.baud = baud
}

func (l *Led485ConfigStruct) GetReadTimeout() time.Duration {
	return l.readTimeout
}

func (l *Led485ConfigStruct) SetReadTimeout(readTimeout time.Duration) {
	l.readTimeout = readTimeout
}

// GetLed485Info returns the Led485Info field.
func (l *Led485ConfigArrayStruct) GetLed485Info() []*Led485ConfigStruct {
	return l.led485Info
}

// SetLed485Info sets the Led485Info field to the provided value.
func (l *Led485ConfigArrayStruct) SetLed485Info(value []*Led485ConfigStruct) {
	l.led485Info = value
}
func (c *CameraInfoStruct) GetLedChannel() string {
	return c.ledChannel
}

func (c *CameraInfoStruct) SetLedChannel(ledChannel string) {
	c.ledChannel = ledChannel
}

func (c *CameraInfoStruct) GetOpenChannel() string {
	return c.openChannel
}

func (c *CameraInfoStruct) SetOpenChannel(outChannel string) {
	c.openChannel = outChannel
}
func (c *CameraInfoStruct) GetLedAddress() string {
	return c.ledAddress
}
func (c *CameraInfoStruct) SetLedAddress(address string) {
	c.ledAddress = address
}
func (l *Led485ConfigStruct) GetAddress() string {
	return l.address
}

func (l *Led485ConfigStruct) SetAddress(address string) {
	l.address = address
}

func (c *CameraInfoStruct) GetOnline() bool {
	return c.online
}

func (c *CameraInfoStruct) SetOnline(online bool) {
	c.online = online
}
